package com.nexgo.data.entity;

import com.nexgo.data.json.JsonRecData;
import com.nexgo.iso8583.Message;
import com.nexgo.iso8583.exception.WriteException;

import java.util.Arrays;

/**
 * Created by xiaox on 2017/6/2.
 */


public class RecvData extends ReqRespEntity {

    private Message message;
    private JsonRecData jsonRecData;

    public JsonRecData getJsonRecData() {
        return jsonRecData;
    }

    public void setJsonRecData(JsonRecData jsonRecData) {
        this.jsonRecData = jsonRecData;
    }

    public void setMessage(Message message) {
        this.message = message;
    }

    /**
     * 返回参与计算mac的数据
     * @return
     */
    public byte[] getOperateData() {
        if (message != null) {
            byte[] respHexValue = new byte[8];
            try {
                respHexValue = message.writeData();
            } catch (WriteException e) {
                e.printStackTrace();
            }
            return Arrays.copyOfRange(respHexValue, 0, respHexValue.length - 8);
        }
        return new byte[8];
    }
}
